﻿Public Class frmCapture
    Public pStart As New Point
    Public pEnd As New Point
    Public bDrag As Boolean = False
    Public pCurrent As String = ""
    Public pForm As Form

    Private Sub frmCapture_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Form1.Visible = True
        pForm.Visible = True
    End Sub


    Private Sub frmCapture_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form1.Visible = False

        pForm.Visible = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Tag = Nothing
        Me.Close()
    End Sub

    Private Sub frmCapture_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        ''select point
        'If (Math.Abs(MousePosition.X - pStart.X) < 5) And (Math.Abs(MousePosition.Y - pStart.Y) < 5) Then
        '    pCurrent = "start"
        '    pStart.Y = MousePosition.Y
        '    pStart.X = MousePosition.X
        '    bDrag = True
        'ElseIf (Math.Abs(MousePosition.X - pEnd.X) < 5) And (Math.Abs(MousePosition.Y - pEnd.Y) < 5) Then
        '    pCurrent = "end"
        '    pEnd.Y = MousePosition.Y
        '    pEnd.X = MousePosition.X
        '    bDrag = True
        'End If
    End Sub


    Private Sub frmCapture_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        'If bDrag Then
        '    If pCurrent = "end" Then
        '        pEnd.X = MousePosition.X
        '        pEnd.Y = MousePosition.Y
        '    Else
        '        pStart.X = MousePosition.X
        '        pStart.Y = MousePosition.Y
        '    End If
        'End If
    End Sub

    Private Sub frmCapture_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        'bDrag = False
        'If pCurrent = "end" Then
        '    pEnd.X = MousePosition.X
        '    pEnd.Y = MousePosition.Y
        'Else
        '    pStart.X = MousePosition.X
        '    pStart.Y = MousePosition.Y
        'End If
    End Sub

    Private Sub frmCapture_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        'Dim g As Graphics = e.Graphics
        'Dim rect As New Rectangle(pStart, New Size(pEnd.X - pStart.X, pEnd.Y - pStart.Y))
        'Dim bPink As Brush = New SolidBrush(Color.FromArgb(50, Color.PaleVioletRed))
        'Dim bDark As Brush = New SolidBrush(Color.FromArgb(100, 0, 0, 0))

        'g.FillRectangle(bDark, New Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height))

        'g.FillRectangle(bPink, rect)
        'g.DrawRectangle(Pens.Black, rect)

        'g.FillRectangle(Brushes.White, New Rectangle(pStart.X - 2, pStart.Y - 2, 5, 5))
        'g.DrawRectangle(Pens.Black, New Rectangle(pStart.X - 2, pStart.Y - 2, 5, 5))

        'g.FillRectangle(Brushes.White, New Rectangle(pEnd.X - 2, pEnd.Y - 2, 5, 5))
        'g.DrawRectangle(Pens.Black, New Rectangle(pEnd.X - 2, pEnd.Y - 2, 5, 5))

        'g.Dispose()
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim iWidth As Integer = My.Computer.Screen.WorkingArea.Width
        Dim iHeight As Integer = My.Computer.Screen.WorkingArea.Height

        Dim screenImage As New Bitmap(iWidth, iHeight)
        Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenImage)
        g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(iWidth, iHeight))
        g.Dispose()
        Me.Tag = screenImage
        Me.Close()
    End Sub
End Class